﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Entity;
using System.Data;

namespace Core.Dao
{
    class DepartmentTicketCategoryDao
    {
        public bool insert(DepartmentTicketCategory departmentTicketCategory)
        {
            object[,] param = {
                {"@DepartmentId", departmentTicketCategory.DepartmentId},
                {"@TicketCategoryId", departmentTicketCategory.TicketCategoryId},
            };
            String sql = "insert into DEPARTMENTTICKETCATEGORIES(DEP_ID, TCK_ID) " +
                "values(@DepartmentId, @TicketCategoryId)";
            return DB.exec(sql, param);
        }

        public bool update(DepartmentTicketCategory departmentTicketCategory)
        {
            object[,] param = {
                {"@DepartmentId", departmentTicketCategory.DepartmentId},
                {"@TicketCategoryId", departmentTicketCategory.TicketCategoryId},
                {"@id", departmentTicketCategory.Id},
            };
            String sql = "update DEPARTMENTTICKETCATEGORIES set DEP_ID = @DepartmentId, TCK_ID = @TicketCategoryId " +
                "where DTC_ID = @id";
            return DB.exec(sql, param);
        }

        public bool delete(int id)
        {
            object[,] param = {
                {"@id", id}   
            };
            String sql = "delete from DEPARTMENTTICKETCATEGORIES where DTC_ID = @id";
            return DB.exec(sql, param);
        }

        public bool delete(String ids)
        {
            object[,] param = {
                {"@ids", ids}   
            };
            String sql = "delete from DEPARTMENTTICKETCATEGORIES where DTC_ID in (" + ids + ")";
            return DB.exec(sql);
        }

        public DataTable get(int id)
        {
            object[,] param = {
                {"@id", id}   
            };
            String sql = "select * from DEPARTMENTTICKETCATEGORIES where DTC_ID = @id";
            return DB.getData(sql, param);
        }

        public DataTable getAll()
        {
            String sql = "select * from DEPARTMENTTICKETCATEGORIES";
            return DB.getData(sql);
        }
    }
}
